{extend name='public/content'}

{block name="title"}
	立即下单
{/block}

{block name="body"}
	
<a href="{:url('index/user/savedizhi')}">新增地址</a>
<style type="text/css">
	.defaultaddress{
		background-color: #30e0af
	}
</style>
<div id="address">
		
		<!-- <div class="defaultaddress">
			<span>姚鹏</span> 
			<span>15588680183</span>
			<span>甘肃省白影视</span>
		</div>
		<div>
			<span>姚鹏</span> 
			<span>15588680183</span>
			<span>甘肃省白影视</span>
		</div> -->
</div>

<div class="layui-container">  
			<div class="layui-row">
			    <div class="layui-col-md6">
			     	{$goods.name}
			    </div>
			    <div class="layui-col-md6">
			      <img src="{$goods.logo}" style="width: 100px;height: 100px">
			    </div>
			</div>
</div>

	{$goods.description}
	属性:
	{$store_goods_stock.spec_title}
	数量:{$data.sum}
	单价：{$data.goods_price}
	总价：{$data.sum_price}
<?php //echo htmlspecialchars_decode($goods['detail']); ?>

<div>选择支付类型</div>
<form>
	<input type="text" name="goods_id"  data-detail="商品ID" value="{$data.goods_id}">
	<div>数量</div>
	<input type="text" name="sum"  data-detail="数量" value="{$data.sum}">
	<div>用户uid</div>
	<input type="text" name="uid"  data-detail="用户uid" value="{$data.uid}">
	<div>价格</div>
	<input type="text" name="goods_price"  data-detail="价格" value="{$data.goods_price}">
	<div>门店</div>
	<input type="text" name="storeid" data-detail="门店" value="{$data.storeid}">
	<div>总价格</div>
	<input type="text" name="sum_price" data-detail="总价格" value="{$data.sum_price}">
	<div>地址id 放在隐藏域中</div>
	<input type="text" name="dress" data-detail="地址id" value="">
	<div>商品属性id</div>
	<input type="text" name="goods_spec_detail" data-detail="商品属性id" value="{$data.goods_spec_detail_id}">
	<div>门店库存id</div>
	<input type="text" name="store_goods_stock" data-detail="门店库存id" value="{$data.store_goods_stock_id}">
</form>
<button class="postorder">提交订单</button>
{/block}
{block name="script"}
 	<script type="text/javascript">
 		
 		 require(['jquery'], function () {
		 	var url={
	 			adrelist:"{:url('index/user/ajaxaddreslist')}",	
	 			addorder:"{:url('index/order/addorder')}",
	 			pay:"{:url('index/order/orderpay')}",
	 		}
	 		/**
	 		 * 刚进去就是ajax获取地址列表，如果不对就增加地址
	 		 * @type {[type]}
	 		 */
 		 	$.ajax({
 		 		url: url.adrelist,
 		 		type: 'GET',
 		 		dataType: 'json',
 		 		data: {},
 		 	})
 		 	.done(function(data) {
 		 		if(data.status=="1"){
 		 			let html = '';
	 		 		for (var i = data.data.length - 1; i >= 0; i--) {
	 		 			// let id =data.data[i].id;
	 		 			// if( data.data[i].is_default == 1 ){
	 		 			// 	$('input[name=dress]').val(id);
	 		 			// }
	 		 			let findOnedata = data.data[i];
	 		 			if(findOnedata.is_default == 1){
	 		 				$('input[name=dress]').val(findOnedata.id);
	 		 				html += '<div class="defaultaddress">' ;
	 		 			}else{
	 		 				html += '<div class="">' ;
	 		 			}
							html += '		<span>' + findOnedata.consignee + '</span>   ';
							html += '		<span>' + findOnedata.city + findOnedata.area + findOnedata.address  + '</span>';						
						if(findOnedata.is_default == 1){
	 		 			  html += '		<span>默认地址</span>';
	 		 			}
						html += '  </div>'
	 		 		}
	 		 		$('#address').append(html);
 		 		}
 		 		if(data.status=="0"){
 		 			alert(32);
 		 			window.location.href= "{:url('index/user/savedizhi')}";
 		 		}
 		 	})
 		 	.fail(function() {
 		 		console.log("error");
 		 	})
 		 	.always(function() {
 		 		
 		 	});


 		 	/**
 		 	 * 操作js去选择用户地址
 		 	 */
 		 	$('.postorder').click(function(){
 		 		var ser = $('form').serialize();
 		 		
 		 		$.ajax({
 		 			url: url.addorder,
 		 			type: 'POST',
 		 			dataType: 'json',
 		 			data: $('form').serialize(),
 		 		})
 		 		.done(function(data) {
 		 			if(data.status==1){
 		 				window.location.href=url.pay+"?id="+data.data;
 		 			}
 		 			else{
 		 				alert("下单出错");
 		 			}
 		 			
 		 		})
 		 		.fail(function() {
 		 			
 		 		})
 		 		.always(function() {
 		 			
 		 		});
 		 		
 		 	})

 		 })


 	</script>
{/block}

{block name="style"}
 <style type="text/css">
 	
 </style>
{/block}